package com.share.demo.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @desc:
 * @author:caifan
 * @date:2020/4/19
 */
public class ThreadTest {
    private int num = 10;
    Object obj;
    Lock lock = new ReentrantLock();
    public static void main(String[] args) {
        ThreadTest threadTest = new ThreadTest();
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        for (int i=0;i<10;i++) {
            executorService.submit(() -> {
                threadTest.sub();
                System.out.println(threadTest.num);
            });
        }
    }

    public void sub() {
        lock.lock();
        num--;
        lock.unlock();

    }


}
